package com.zqh.apiuseraddrquery.controller;

import com.zqh.apiuseraddrquery.redis.RedisUtil;
import com.zqh.myfmmall.clients.UserAddrQueryClient;
import com.zqh.myfmmall.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description :
 * @Author :kono淇杭哒、
 * @Create 2022-03-05 23:00
 */
@RestController
@RequestMapping("userAddr/query")

public class ApiUserAddrQueryController{
    /**
     * 服务对象
     */
    @Autowired
    private UserAddrQueryClient userAddrQueryClient;
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private RedisUtil redisUtil;

    @PostMapping("list")
    public Result retrieveByUid(){
        String token = request.getHeader("token");
        String userId = (String) redisUtil.get(token);
        Result result = userAddrQueryClient.getByUid(userId);
        return result;
    }

    @GetMapping("retrieve/{addrId}")
    public Result retrieve(@PathVariable("addrId") String addrId){
        Result result = userAddrQueryClient.getById(addrId);
        return result;
    }
}
